//
//  YCAppContext.swift
//  YCNetworking
//
//  Created by YC on 2017/3/7.
//  Copyright © 2017年 YC. All rights reserved. mail:yangchong364@qq.com
//

import UIKit
import Alamofire

public class YCAppContext {
    public static let shared = YCAppContext()
    
    public private(set) var isReachable = true
    public var apiType: YCApiType = .online
    
    private var manager: NetworkReachabilityManager = NetworkReachabilityManager(host: "www.baidu.com")!
    
    private init() {
        self.manager.listener = { status in
            
            switch status {
            case .notReachable:
                self.isReachable = false
            case .unknown:
                self.isReachable = false
            case .reachable(.ethernetOrWiFi):
                self.isReachable = true
            case .reachable(.wwan):
                self.isReachable = true
            }
            
            NSLog("网络状态发生变化: \(status)")
        }
        
        self.manager.startListening()
    }
}
